#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1000;

string name[N];
string number[N];
int grade[N];

int main(){
    int n;
    int high_grade_index = 0;
    int low_grade_index = 0;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> name[i] >> number[i]  >> grade[i];
        if(i > 0){
            if(grade[i] > grade[high_grade_index]){
                high_grade_index = i;
            }else if(grade[i] < grade[low_grade_index]){
                low_grade_index = i;
            }
        }
    }

    cout << name[high_grade_index] << " " << number[high_grade_index] << endl;
    cout << name[low_grade_index] << " " << number[low_grade_index] << endl;
    return 0;
}